// 大数据第五题
// author ： lbc
package homework1;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.text.SimpleDateFormat;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.LocatedFileStatus;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.RemoteIterator;

public class catDirInfo {
    public static void main(String[] args) throws IOException, URISyntaxException {
        Configuration conf = new Configuration();
        String hdfsPath = "hdfs://localhost:9000";
        FileSystem hdfs = FileSystem.get(new URI(hdfsPath), conf);
        String filePathHdfs = "hdfstest";
        getInfoRecursive(hdfs, filePathHdfs);
        hdfs.close();
    }
    public static void getInfoRecursive(FileSystem fs, String file_path) throws IOException {
        Path dir_path = new Path(file_path);
        boolean recursive = true;
        RemoteIterator<LocatedFileStatus> fileinfos = fs.listFiles(dir_path, recursive);
        while(fileinfos.hasNext()){
            FileStatus fileinfo = fileinfos.next();
            System.out.println("************************************");
            SimpleDateFormat format = new SimpleDateFormat("HH: mm yyyy-MM-dd");
            System.out.println("Path: " + fileinfo.getPath().toString());
            System.out.println("Permission: " + fileinfo.getPermission().toString());
            System.out.println("Size: " + fileinfo.getLen());
            System.out.println("Time: " + format.format(fileinfo.getModificationTime()));
        }
    }
    
}
